<?php
/**
 * Created by PhpStorm.
 * User: wo
 * Date: 2019/9/19
 * Time: 18:11
 */
class Wish_logModel extends BaseModel
{
    var $table = 'wish_log';
    var $prikey = 'id';
    var $_name = 'wish_log';
    var $_relation  = array(
        'has_member' => array(
            'model'         => 'member',
            'type'          => BELONGS_TO,
            'foreign_key'   => 'inviter_id',
            'reverse' => 'user_wish_log',
        ),
    );


    //获取邀请人砍价金额
    function getInvalid($id,$where=null){
        if($where){
            return $this->getOne("select sum(money) from ecm_wish_log where wish_id = ".$id.' AND stage IN (1,2)');
        }
        return $this->getOne("select sum(money) from ecm_wish_log where wish_id = ".$id);
    }
    //获取邀请人人数总数
    function getCounts($id){
        return $this->getOne("select count(*) from ecm_wish_log where wish_id = ".$id);
    }
    //求总数
    function getTemplateCount($where){
        return $this->
        getOne
        ('select count(*) from ecm_wish_log where wish_id = '.$where['wish_id'].' AND sign ='."'".$where['sign']."'".' AND stage = '.$where['stage']);
    }

}